﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using Newtonsoft.Json;
using System.Data.Entity.Infrastructure;
using _24_Hour_Blogger.Models;
using _24_Hour_Blogger.Models.Content;
using _24_Hour_Blogger.Library;

namespace _24_Hour_Blogger.ViewModels.Content
{
    public partial class BlogViewModel : ViewModelBase<Blog>
    {

        public BlogViewModel()
        {
            this.Entity = new Blog();
        }

        DbContext dataContext = null;
        DbSet<Blog> entitiesCollection = null;
        Blog entityClass = null;
        public BlogViewModel(DbContext dataContext, DbSet<Blog> entitiesCollection, Blog entityClass)
        //: base(dbContext, entitiesCollection, entityClass)
        {

            this.dataContext = dataContext;
            this.entitiesCollection = entitiesCollection;
            this.entityClass = entityClass;
            if (this.entityClass == null)
            {
                this.entityClass = new Blog();
            }
            this.Entity = this.entityClass;
        }

        public override Int32 Id
        {
            get
            {
                return Entity.BlogId;
            }
            set
            {

                Entity.BlogId = value;


            }
        }

        public Int32 BlogId
        {
            get
            {
                return Entity.BlogId;
            }
            set
            {
                if (value > 0)

                    if (Entity.BlogId != value)
                    {
                        Entity.BlogId = value;
                        this.IsDirty = true;
                    }
            }
        }

        public String BlogName
        {
            get
            {
                return Entity.BlogName;
            }
            set
            {
                if (Entity.BlogName != value)
                {
                    Entity.BlogName = value;
                    this.IsDirty = true;
                }
            }
        }

        public String BlogUrl
        {
            get
            {
                return Entity.BlogUrl;
            }
            set
            {
                if (Entity.BlogUrl != value)
                {
                    Entity.BlogUrl = value;
                    this.IsDirty = true;
                }
            }
        }

        public String Description
        {
            get
            {
                return Entity.Description;
            }
            set
            {
                if (Entity.Description != value)
                {
                    Entity.Description = value;
                    this.IsDirty = true;
                }
            }
        }

        public String Keywords
        {
            get
            {
                return Entity.Keywords;
            }
            set
            {
                if (Entity.Keywords != value)
                {
                    Entity.Keywords = value;
                    this.IsDirty = true;
                }
            }
        }

        public String Synopsis
        {
            get
            {
                return Entity.Synopsis;
            }
            set
            {
                if (Entity.Synopsis != value)
                {
                    Entity.Synopsis = value;
                    this.IsDirty = true;
                }
            }
        }

        public int PrimaryCategoryId
        {
            get
            {
                return Entity.PrimaryCategoryId;
            }
            set
            {
                if (Entity.PrimaryCategoryId != value)
                {
                    Entity.PrimaryCategoryId = value;
                    this.IsDirty = true;
                }
            }
        }

        public int StatusId
        {
            get
            {
                return Entity.StatusId;
            }
            set
            {
                if (Entity.StatusId != value)
                {
                    Entity.StatusId = value;
                    this.IsDirty = true;
                }
            }
        }

        public int UserId
        {
            get
            {
                return Entity.UserId;
            }
            set
            {
                if (Entity.UserId != value)
                {
                    Entity.UserId = value;
                    this.IsDirty = true;
                }
            }
        }

        public override DateTime CreatedDate
        {
            get
            {
                return Entity.CreatedDate;
            }
            set
            {
                if (Entity.CreatedDate != value)
                {
                    Entity.CreatedDate = value;
                    this.IsDirty = true;
                }
            }
        }

        public override DateTime UpdatedDate
        {
            get
            {
                return Entity.UpdatedDate;
            }
            set
            {
                if (Entity.UpdatedDate != value)
                {
                    Entity.UpdatedDate = value;
                    this.IsDirty = true;
                }
            }
        }

        public override Int32 CreatedByUserId
        {
            get
            {
                return Entity.CreatedByUserId;
            }
            set
            {
                if (Entity.CreatedByUserId != value)
                {
                    Entity.CreatedByUserId = value;
                    this.IsDirty = true;
                }
            }
        }

        public override Int32 UpdatedByUserId
        {
            get
            {
                return Entity.UpdatedByUserId;
            }
            set
            {
                if (Entity.UpdatedByUserId != value)
                {
                    Entity.UpdatedByUserId = value;
                    this.IsDirty = true;
                }
            }
        }

        private DataCollectionBase<ArticleViewModel, Article> _Articles;
        [JsonIgnore]
        public DataCollectionBase<ArticleViewModel, Article> Articles
        {
            get
            {
                if (_Articles == null)
                {
                    if (this.Entity != null && dataContext != null)
                        _Articles = new DataCollectionBase<ArticleViewModel, Article>(dataContext, DataStore.ContentEntities.Articles, this.Entity.Articles);
                    else
                        _Articles = null;
                }

                return _Articles;
            }
            set
            {
                _Articles = value;
            }
        }

    }
}